/*
 *
 * CameraFilter.java
 * 
 * Created by Wuwang on 2016/11/19
 * Copyright © 2016年 深圳哎吖科技. All rights reserved.
 */
package com.wk.camerapreviewwithfilter.filter;

import android.content.res.Resources;
import android.opengl.GLES11Ext;
import android.opengl.GLES20;

import java.util.Arrays;


/**
 * Description:
 */
public class OesFilter extends AFilter {

    private int mHCoordMatrix;
    private float[] mCoordMatrix = Arrays.copyOf(OM, 16);
    private int hChangeType;
    private int hChangeColor;
    private Filter mFilter;
    public OesFilter(Resources mRes, Filter filter) {
        super(mRes);
        this.mFilter = filter;
    }

    public void setFilter(Filter filter) {
        mFilter = filter;
    }

    @Override
    protected void onCreate() {
        createProgramByAssetsFile("oes_base_vertex.sh", "oes_base_fragment.sh");
        mHCoordMatrix = GLES20.glGetUniformLocation(mProgram, "vCoordMatrix");
        hChangeType= GLES20.glGetUniformLocation(mProgram,"vChangeType");
        hChangeColor= GLES20.glGetUniformLocation(mProgram,"vChangeColor");
    }

    public void setCoordMatrix(float[] matrix) {
        this.mCoordMatrix = matrix;
    }

    @Override
    protected void onSetExpandData() {
        super.onSetExpandData();
        GLES20.glUniformMatrix4fv(mHCoordMatrix, 1, false, mCoordMatrix, 0);
        GLES20.glUniform1i(hChangeType,mFilter.getType());
        GLES20.glUniform3fv(hChangeColor,1,mFilter.data(),0);
    }

    @Override
    protected void onBindTexture() {
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + getTextureType());
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, getTextureId());
        GLES20.glUniform1i(mHTexture, getTextureType());
    }

    private static final String TAG = "OesFilter";

    @Override
    protected void onSizeChanged(int width, int height) {

    }

}
